package com.laozhao.test;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

public class CardLayoutDemo extends JFrame implements ActionListener {


	CardLayout card = new CardLayout();
	JPanel mainPanel = new JPanel();
	int mun = 0;
	JButton addButton = new JButton("ADD");
	
	public CardLayoutDemo() {
		
		getContentPane().setLayout(new BorderLayout());
		getContentPane().add(mainPanel , BorderLayout.CENTER);
		getContentPane().add(addButton,BorderLayout.NORTH);
		addButton.addActionListener(this);
		
		mainPanel.setLayout(card);

		
	}

	public void actionPerformed(ActionEvent evt) {
		mun ++ ;
		JPanel xJPanel = new JPanel();
		if (mun%2 == 0) {
			xJPanel.setBackground(Color.red);
		}else {
			xJPanel.setBackground(Color.BLACK);
		}
		
		mainPanel.add(String.valueOf(mun), xJPanel);
		card.show(mainPanel, String.valueOf(mun));
	}

	public static void main(String[] args) {
		// JFrame.setDefaultLookAndFeelDecorated(true);

//		JFrame frame = new JFrame();
//		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		CardLayoutDemo demo = new CardLayoutDemo();
		// demo.addCardsToPane(frame.getContentPane());
		// demo.addCardsToPane();

		demo.pack();
		demo.setVisible(true);
	}
}
